options compress=YES;
libname manasi ''; 
libname earn '';

* MERGE PARENTAL EARNINGS INTO MAIN DATA SET;
%macro merge(exp);
proc sort data=manasi.&exp. out=manasi.&exp.;
	by hun;
run;

data earn.&exp._earn;
	merge 
		manasi.&exp.
			(in=frommainx)
		earn.par_earn_hunmerge_wide 
			(keep=
				hun 
				n_hhearns0206_1985-n_hhearns0206_2011
			in=fromparearnx)
	;
	by hun;
	frommain = frommainx;
	fromparearn = fromparearnx;
run;

data earn.&exp._earn;
	set earn.&exp._earn(where=(frommain=1));
run;

%mend merge;

%merge(analysis_cdrdrop040506_med);
%merge(kids_complier_all0405);
%merge(analysis04_entryrd);

%let EARN_DIR=\\s102a6a\osas$\DPE_Secure\Manasi\earnings;
libname earn "&EARN_DIR";

%macro stataexport(dsname);
proc export data=earn.&dsname
     file="&EARN_DIR\&dsname..dta"
     dbms=DTA REPLACE;
run;
%mend stataexport;

%stataexport(analysis_cdrdrop040506_med_earn);
%stataexport(kids_complier_all0405);
%stataexport(analysis04_entryrd_earn);

Run; 
